package com.ganzi.ganziserver.utils;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class GetTime {


    public static Timestamp getNowTime(){
        SimpleDateFormat dtformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar cal_1 = Calendar.getInstance();
        String nowTime = dtformat.format(cal_1.getTime());//今天
        return Timestamp.valueOf(nowTime);
    }
    public static Long getNowTimeForLong(){
        SimpleDateFormat dtformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar cal_1 = Calendar.getInstance();
        String nowTime = dtformat.format(cal_1.getTime());//今天
        Timestamp temp = Timestamp.valueOf(nowTime);
        return temp.getTime();
    }
    public static Timestamp getBeforMonthNowTime(){
        SimpleDateFormat dtformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar cal_1 = Calendar.getInstance();
        cal_1.add(Calendar.MONTH, -1);
        String nowTime = dtformat.format(cal_1.getTime());//上个月今天
        return Timestamp.valueOf(nowTime);
    }
    /*
     * 将时间戳转换为时间
     */
    public static String stampToDate(long s){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        res = simpleDateFormat.format(s);
        return res;
    }

}
